package com.szbber.medical.board.viewModel

import android.content.Context
import androidx.lifecycle.MutableLiveData
import com.orhanobut.logger.Logger
import com.szbber.commen.api.Repository
import com.szbber.commen.api.launch
import com.szbber.commen.base.BaseViewModel
import com.szbber.commen.bean.AddMessageBean
import com.szbber.commen.bean.MessageListBean

class MessageInfoViewModel : BaseViewModel() {


    val messageBean = MutableLiveData<MessageListBean>()
    fun getMessageList(context: Context?, patientId:String?) = launch(context,{
        val queue = arrayOf("patientId", patientId)
        messageBean.value=  Repository.getMessageList(context,*queue)
    })

    fun addMessage(context: Context?, addMessageBean: AddMessageBean?) = launch(context, {
        var queue = emptyArray<String>()
        addMessageBean?.patientId?.apply {
            queue = queue.plus("patientId")
            queue = queue.plus(this)
        }
        addMessageBean?.title?.apply {
            queue = queue.plus("title")
            queue = queue.plus(this)
        }
        addMessageBean?.context?.apply {
            queue = queue.plus("context")
            queue = queue.plus(this)
        }
        addMessageBean?.imgurl?.apply {
            queue = queue.plus("imgurl")
            queue = queue.plus(this)
        }
        addMessageBean?.fileurl?.apply {
            queue = queue.plus("fileurl")
            queue = queue.plus(this)
        }
        addMessageBean?.type?.apply {
            queue = queue.plus("type")
            queue = queue.plus(this)
        }

        Repository.addMessage(context, *queue)
        getMessageList(context, addMessageBean?.patientId)
    })

}